fix: Fix variable-assign-node cannot publish#2418
Conversation
--bug=1052464 --user=刘瑞斌 【应用】-编排应用中存在变量赋值节点,发布应用失败 https://www.tapd.cn/57709429/s/1659401
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| return Promise.all(ps).catch((err: any) => { | ||
| return Promise.reject({ node: props.nodeModel, errMessage: err }) | ||
| }) | ||
| } |
There was a problem hiding this comment.
The provided code is mostly correct, but there's an issue with the structure of the nodeCascaderRef2 mapping function when it might be undefined. It uses ...[] which can lead to unexpected behavior due to type widening if nodeCascaderRef2.value is not defined.
Here are some recommendations:
-
Check for Undefined Value: Before attempting to map on
nodeCascaderRef2, ensure that it exists. This prevents errors from occurring when calling.map()on an undefined value. -
Optimization: The current implementation will execute
validate()calls serially instead of parallel for bothreplyNodeFormRefand each option innodeCascaderRef. If you want to execute them in series, keep the existingPromise.all([...]).catch(). However, this ensures they are executed one after another without changing their order. -
Example Code:
const validate = async () => {
let errorCount = 0;
const allValidationsPromises = [
replyNodeFormRef.value?.validate().then(() => {
// Count validation success for replyNodeFormRef
errorCount++;
}).catch(err => {
console.error('Validation failed:', err);
errorCount++;
}),
...nodeCascaderRef.value?.map(item => item.validate()).map(validateResult => {
if (!validateResult.validated) { // Assuming each cascader node has a validated property indicating successful validation
// Mark error for cascader nodes
errorCount++;
}
return validateResult;
}) || []
];
await Promise.all(allValidationsPromises);
if (errorCount === 0) {
logger.info(`All validations passed.`);
} else {
throw new Error(`Failed to verify the form details: ${errorCount} errors found.`);
}
};- Error Handling: Ensure proper handling within
catch()blocks. In the example above, if there are no validations failures (errorCount === 0) it logs a success message; otherwise, it throws an exception detailing how many checks failed.
These improvements help manage edge cases such as uninitialised references more gracefully, avoiding runtime TypeScript errors during evaluation.
fix: Fix variable-assign-node cannot publish --bug=1052464 --user=刘瑞斌 【应用】-编排应用中存在变量赋值节点,发布应用失败 https://www.tapd.cn/57709429/s/1659401